package thread;
/**
 * 使用匿名内部类形式实现线程的两种创建方式
 */
public class ThreadDemo3 {
    public static void main(String[] args) {
        //第一种创建方式:继承Thread并重写run方法
        Thread t1 = new MyThread1(){
            public void run(){
                for (int i = 0; i < 1000; i++){
                    System.out.println("早");
                }
            }
        };
        t1.start();
        //第二种创建方式: 实现Runnable接口并重写run方法
        Runnable r = new Runnable(){
            public void run(){
                for (int i = 0; i < 1000; i++){
                    System.out.println("早上好");
                }
            }
        };
        Thread t2 = new Thread(r);
        t2.start();
        Thread t3 = new Thread(()->{
                for (int i = 0; i < 1000; i++){
                    System.out.println("大家早上好");
                }
            });
        t3.start();
    }
}
